﻿using System;
using System.Windows.Forms;
using Common;
using System.Linq;
using DataLibrary;

namespace TicketSystem
{
    public partial class Form_Main : Form
    {
        public Form_Main()
        {
            InitializeComponent();
        }
        private UC_Ticket ticket;
        private UC_Reports report;//旅行社日报表
        private TicketSystemEntities tse = new TicketSystemEntities();
        private void Main_Load(object sender, EventArgs e)
        {
            ticket = new UC_Ticket();
            report = new UC_Reports();
            int id = GetOperator.OperatorID;
            this.tool_operator.Text = "操作员：" + GetOperator.OperatorName;
            this.tool_time.Text = "系统时间：" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            this.timer1.Interval = 1000;
            this.timer1.Start();
            ticket.Show();
            gpb_Windows.Controls.Clear();
            gpb_Windows.Controls.Add(ticket);
        }

        private void 旅行社日报表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gpb_Windows.Controls.Clear();
            ticket = new UC_Ticket();
            report = new UC_Reports();
            report.ReportType = 1;
            report.Show();
            gpb_Windows.Controls.Add(report);            
        }

        private void 日报表明细ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gpb_Windows.Controls.Clear();
            ticket = new UC_Ticket();
            report = new UC_Reports();
            report.ReportType = 2;
            report.Show();            
            gpb_Windows.Controls.Add(report); 
        }

        private void 时段报表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ticket = new UC_Ticket();
            report = new UC_Reports();
            report.ReportType = 3;
            report.Show();
            gpb_Windows.Controls.Clear();
            gpb_Windows.Controls.Add(report); 
        }

        private void 系统日结ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_Checkout f_Checkout = new Form_Checkout();
            f_Checkout.StartPosition = FormStartPosition.CenterParent;
            f_Checkout.ShowDialog();
        }

        private void timer1_Tick(object sender, EventArgs e)        
        {
            this.tool_time.Text = "当前系统时间：" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        private void 日结记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tse.Checkouts.Count() > 0)
            {
                Form_CheckoutLog f_log = new Form_CheckoutLog();
                f_log.StartPosition = FormStartPosition.CenterParent;
                f_log.ShowDialog();
            }
            else
            {
                MessageBox.Show("尚无任何结账记录");
            }
        }
        

        private void 系统管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_SystemManage sm = new Form_SystemManage();
            sm.StartPosition = FormStartPosition.CenterParent;
            sm.ShowDialog();
        }

        private void 前台开票ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ticket.Show();
            gpb_Windows.Controls.Clear();
            gpb_Windows.Controls.Add(ticket);
        }

        private void 订单查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_Search fs = new Form_Search();
            fs.StartPosition = FormStartPosition.CenterParent;
            fs.ShowDialog();
        }

        private void 退单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_Back f_back = new Form_Back();
            f_back.StartPosition = FormStartPosition.CenterParent;
            f_back.ShowDialog();
        }
        
        private void 报表管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gpb_Windows.Controls.Clear();
            ticket = new UC_Ticket();
            report = new UC_Reports();
            report.Show();
            gpb_Windows.Controls.Add(report); 
        }

        private void managerReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!FormShow.f_manager)
            {
                if (GetOperator.OperatorName.ToLower() == "admin")
                {
                    FormShow.f_manager = true;
                    Form_Manager fm = new Form_Manager();
                    fm.StartPosition = FormStartPosition.CenterParent;
                    fm.Show();                    
                }
                else
                {
                    MessageBox.Show("您的账号没有权限使用此功能");
                }
            }
            else
            {
                MessageBox.Show("窗口已打开");
            }
        }

        private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }
    }
}
